<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 300px;
            height: 300px;
            margin: 100px auto;
            color: rgb(24, 166, 206);
        }
    </style>
</head>

<body>
    <div class="box"></div>
</body>

</html>
<script>
    //封装一个函数，创建ajax
    function ajax(manner, url, cb) {

        // 创建一个ajax对象
        let xhr = new XMLHttpRequest()

        // 设置xhr对象请求方式，请求地址
        xhr.open(manner, url)

        // 设置回调函数
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4) {
                cb(JSON.parse(xhr.responseText))

            }
        }

        // 发送请求
        xhr.send()
    }

    let box = document.querySelector('.box')
    ajax('get', './ajax.json', function (cb) {
        console.log(cb);
        let str = ``
        str = cb.list.map((item, index) => {
            return `<li>${item}</li>`
        }).join('')
        box.innerHTML = str
    })
</script>